package com.xoms.front.controller.springmvc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.*;
import com.xoms.front.controller.res.*;
import com.xoms.front.controller.res.bean.*;
import com.xoms.front.controller.springmvc.req.*;

/**
 * 支付相关接口
 **/
@Controller
@RequestMapping(value = "/pay", produces = "application/json")
public class SPayController {
	@Autowired
	com.xoms.front.controller.PayController payController;

	/**
	 * 微信刷卡支付
	 **/
	@RequestMapping("/v1/wxScanAuthCode")
	@ResponseBody
	public BaseResult wxScanAuthCode(@Validated GetWXScanAuthCode2StoreParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return payController.wxScanAuthCode(param, request, response);
	}

	/**
	 * 微信扫码支付
	 **/
	@RequestMapping("/v1/wxScanQrcode")
	@ResponseBody
	public ObjectResult<String> wxScanQrcode(@Validated GetWXScanQrcode2StoreParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<String> res = new ObjectResult<String>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return payController.wxScanQrcode(param, request, response);
	}

	/**
	 * 支付宝当面付
	 **/
	@RequestMapping("/v1/aliScanAuthCode")
	@ResponseBody
	public BaseResult aliScanAuthCode(@Validated GetALIScanAuthCode2StoreParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return payController.aliScanAuthCode(param, request, response);
	}

	/**
	 * 支付宝扫码支付
	 **/
	@RequestMapping("/v1/aliScanQrcode")
	@ResponseBody
	public ObjectResult<String> aliScanQrcode(@Validated GetALIScanQrcode2StoreParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<String> res = new ObjectResult<String>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return payController.aliScanQrcode(param, request, response);
	}

	/**
	 * 查询订单支付状态
	 **/
	@RequestMapping("/v1/queryOrderStatus")
	@ResponseBody
	public ObjectResult<ROrderStatusBean> queryOrderStatus(@Validated GetQueryOrderStatusParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<ROrderStatusBean> res = new ObjectResult<ROrderStatusBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return payController.queryOrderStatus(param, request, response);
	}
}
